<template>
	<!-- 过账页面(机加过账、装配过账都使用这个页面) -->
	<!-- <v-dialog v-model="postbillModel.showThisFlag">
		<v-card>
			<v-card-title>过账消息</v-card-title>
			<v-card-text>
				<div>
					{{showText}}
				</div>
			</v-card-text>
			<v-card-actions>
				<v-btn color="primary" text depressed @click="textDialog=false">关闭</v-btn>
			</v-card-actions>
		</v-card>
	</v-dialog>
	<div v-if="postbillModel.showThisFlag">
		<div v-if="showInputCompltecountFlag">
			<v-text-field v-model="compltecount" :rules="qtyRule" label="录入完工数量" dense outlined></v-text-field>
			<v-btn width="100%" color="primary" @click="operationStartOrStopOrEnd(compltecount)">提交</v-btn>
		</div>
		<div v-else>
		</div>
	</div> -->
	<div>
		<v-dialog v-model="postbillModel.showThisFlag" persistent max-width="290">
			<v-card>
				<v-card-title>过账消息</v-card-title>
				<v-card-text>
					<div v-if="textDialog">
						{{showText}}
					</div>
					<div v-else>
						<v-text-field v-model="compltecount" :rules="qtyRule" label="录入完工数量" dense outlined>
						</v-text-field>
				<!-- 				<userselectcomment :selectUserCommentModel="userCommentModel" :callBack="setUserCallBack">
						</userselectcomment> -->
						<v-text-field v-model="projectresponsible" label="责任人" dense outlined>
						</v-text-field>
						<v-checkbox v-if="postbillModel.isShowWOutFilag" v-model="wOutFlag" label="是否委外"></v-checkbox>
						<v-btn width="100%" color="primary" @click="operationStartOrStopOrEnd(compltecount)">提交</v-btn>
					</div>
				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn color="primary" text depressed @click="postbillModel.showThisFlag=false">关闭</v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>
	</div>
</template>

<script>
	import UserSelectComment from '../../../spm/components/UserSelect.vue'
	export default {
		name: 'postbill_pda',
		components: {
			userselectcomment: UserSelectComment,
		},
		props: {
			callBackLoadProcessCards: {
				type: Function, //参数类型：函数
			},
			postbillModel: {
				showThisFlag: false,
				workCenterId: 0,
				isShowWOutFilag: false,
				areatype: 0,
				controllerName: '',
				processCardCode: '',
				loadSelectUserItemsUrl: ``
			},
		},
		data: () => ({
			activatedFlag: false,
			wOutFlag: false,
			textDialog: false,
			showText: '',
			//完工数量
			compltecount: 0,
			//责任人
			projectresponsible: null,
			cardId: 0,
			qtyRule: [
				v => /^[0-9]*$/.test(v) || '请输入合法数字',
				v => v >= 0 || '需求量不能小于0'
			],
			userCommentModel: {
				loadSelectUserItemsUrl: ``,
				isReturnObj: false,
				label: '选择责任人',
				paramterUserList: []
			},
		}),

		watch: {
			// MES/${this.postbillModel.controllerName}/GetUserInfoToSelect
			// postbillModel(newVal) {
			// 	this.$emit('update:postbillModel', newVal)		
			// 	this.getProcessCardInfo(newVal)
			// },
			postbillModel: {
				handler(newVal) {
					this.$emit('update:postbillModel', newVal)
					this.userCommentModel.loadSelectUserItemsUrl = this.postbillModel.loadSelectUserItemsUrl
					this.getProcessCardInfo(newVal)
				},
				deep: true
			},
		},
		methods: {
			//获取流程卡信息
			async getProcessCardInfo(newVal) {
				if (!newVal.showThisFlag) {
					return
				}
				//这里为true主要是因为页面加载的比较慢
				this.textDialog = true
				this.showText = ''
				var response = await this.$httpRequest({
					url: `MES/${this.postbillModel.controllerName}/GetProcessCard?processCardCode=${this.postbillModel.processCardCode}`,
					method: 'get',
				})

				if (response.status != 1) {
					this.showText = response.info
					this.$message.error(response.info)
					return
				}
				this.compltecount = response.data.childrenOrder.totalcount - response.data.resultcount
				this.cardId = response.data.id
				var rs = await this.$httpRequest({
					url: `MES/${this.postbillModel.controllerName}/ProcessPosting?
					workcenterid=${this.postbillModel.workCenterId}&
					cardId=${this.cardId}`,
					method: 'get'
				})
				if (rs.status != 1) {
					this.$message.error(rs.info)
					this.showText = rs.info
					return
				}
				//status :50 过账中  status :51 委外暂存待品检
				if (rs.info == '录入数量') {
					this.textDialog = false
					this.showText = ''
				} else //  rs.data.childrenOrder.status == 10 暂停
				{
					this.showText = `工单号:${response.data.childrenOrder.code},已开始过账！`
					//重新加载工作中心的流程卡信息
					this.$props.callBackLoadProcessCards()
				}
			},

			// 流程卡第一个刷,
			//录入完工数量后提交
			//开始过账
			async operationStartOrStopOrEnd() {
				var response = await this.$httpRequest({
					url: `MES/${this.postbillModel.controllerName}/ProcessPosting?
						workcenterid=${this.postbillModel.workCenterId}&
						processCardCode=${this.postbillModel.processCardCode}&
						compltecount=${this.compltecount}&
						projectresponsible=${this.projectresponsible}&
						isWout=${this.wOutFlag}`,
					method: 'get'
				})
				if (response.status == 1) {
					this.refresh()
					this.$message.success('报工完成！')
					this.$props.callBackLoadProcessCards()
				} else {
					this.$message.error(response.info)
				}

			},
			refresh() {
				this.postbillModel.showThisFlag = false
				this.postbillModel.workCenterId = 0
				this.postbillModel.processCardCode = ''
				this.postbillModel.controllerName = ''
				this.textDialog = false
				this.showText = ''
				this.compltecount = 0
				this.projectresponsible = null

			},
			//根据传递过来的参数name获取对应的值
			getParameter(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
				var r = location.search.substr(1).match(reg);
				if (r != null) return (r[2]);
				return null;
			},
			setUserCallBack(user) {
				console.log(user)
				// this.purchaseNeedModel.personcode = user.value
				// this.purchaseNeedModel.personname = user.realname
				// this.purchaseNeedModel.personid = user.id
			},

		}
	}
</script>

<style>
</style>
